import { resolve } from 'path'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import legacy from '@vitejs/plugin-legacy'
import svgLoader from 'vite-svg-loader'

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      dts: 'src/auto-imports.d.ts'
    }),
    legacy({
      targets: ['ie >= 11'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11时需要此插件
    }),
    svgLoader()
  ],
  base: './',
  resolve: {
    alias: [{ find: '@', replacement: resolve(__dirname, './src') }]
  },
  server: {
    host: '0.0.0.0',
    port: 8000,
    proxy: {
      '/api/client': {
        target: 'http://172.30.52.139:8888/api/client',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/client/, '')
      }
    }
  },
  build: {
    target: 'es2015'
  }
})
